<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户信息维护表添加--${site.name}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="${site.description}"/>
    <meta name="keywords" content="${site.keywords}"/>
    <meta name="author" content="${site.author}"/>
    <link rel="icon" href="${site.logo}">
    <link rel="stylesheet" href="${base}/static/layui/css/layui.css" media="all" />
    <style type="text/css">
        .layui-form-item .layui-inline{ width:33.333%; float:left; margin-right:0; }
        @media(max-width:1240px){
            .layui-form-item .layui-inline{ width:100%; float:none; }
        }
        .layui-form-item .role-box {
            position: relative;
        }
        .layui-form-item .role-box .jq-role-inline {
            height: 100%;
            overflow: auto;
        }

    </style>
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
    <div class="layui-form-item">
        <label class="layui-form-label">社会统一信用代码</label>
        <div class="layui-input-block">

            <input  type="text"  class="layui-input" name="creditCode" id="creditCode" lay-verify="required" placeholder="请输入社会统一信用代码">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">企业名称</label>
        <div class="layui-input-block">

            <input  type="text"  class="layui-input" name="conmanyName" lay-verify="required" placeholder="请输入企业名称">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">产业政策调整目录</label>
        <div class="layui-input-block">

            <select name="policyContents"  lay-verify="required" lay-search>
                <option value="" selected="">请选择产业政策调整目录</option>
                <@my type="electricity_user_defend_policy_contents">
                <#list result as r>
                <option value="${r.value}" >${r.label}</option>
                </#list>
                </@my>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addElectricityUserDefend">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="${base}/static/layui/layui.js"></script>
<script>
    layui.use(['form','jquery','layer'],function(){
        var form      = layui.form,
                $     = layui.jquery,
                layer = layui.layer;


        form.on("submit(addElectricityUserDefend)",function(data){

            var loadIndex = layer.load(2, {
                shade: [0.3, '#333']
            });
            var creditCode = $("#creditCode").val();
            var patrn = /^[0-9A-Z]+$/;
            //18位校验及大写校验
            if ((creditCode.length != 18) || (patrn.test(creditCode) == false)){
                layer.alert("不是有效的统一社会信用编码！");
                return;
            }else{
                var Ancode;//统一社会信用代码的每一个值
                var Ancodevalue;//统一社会信用代码每一个值的权重
                var total = 0;
                var weightedfactors = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];//加权因子
                var str = '0123456789ABCDEFGHJKLMNPQRTUWXY';
                //不用I、O、S、V、Z
                for (var i = 0; i < creditCode.length - 1; i++) {
                    Ancode = creditCode.substring(i, i + 1);
                    Ancodevalue = str.indexOf(Ancode);
                    total = total + Ancodevalue * weightedfactors[i];
                    //权重与加权因子相乘之和
                }
                var logiccheckcode = 31 - total % 31;
                if (logiccheckcode == 31)  {
                    logiccheckcode = 0;
                }
                var Str = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,T,U,W,X,Y";
                var Array_Str = Str.split(',');
                logiccheckcode = Array_Str[logiccheckcode];


                var checkcode = creditCode.substring(17, 18);
                if (logiccheckcode != checkcode) {
                    layer.alert("不是有效的统一社会信用编码！");
                    return;
                }
            }




            $.post("${base}/admin/electricityUserDefend/add",data.field,function(res){
                layer.close(loadIndex);
                if(res.success){
                    parent.layer.msg("用户信息维护表添加成功！",{time:1000},function(){
                        parent.layer.close(parent.addIndex);
                        //刷新父页面
                        parent.location.reload();
                    });
                }else{
                    layer.msg(res.message);
                }
            });
            return false;
        });

    });
</script>
</body>
</html>